package edu.hrbu.kwaidu.common;

import lombok.Builder;
import lombok.Getter;

/**
 * @author xudengyu
 */
@Getter
@Builder
public class R {
    // 响应码
    private Integer code;

    // 响应信息
    private String message;

    // 总数量
    private Long count;

    // 响应数据
    private Object data;

    public static final int SUCCESS_CODE = 200;
    public static final int ERROR_CODE = 201;
    public static final String SUCCESS_MESSAGE = "success";
    public static final String ERROR_MESSAGE = "error";
    public static final String SUCCESS_DATA = "操作成功";
    public static final String ERROR_DATA = "操作失败";

    public static R ok() {
        return R.builder().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).data(SUCCESS_DATA).build();
    }

    public static R ok(Object data) {
        return R.builder().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).data(data).build();
    }

    // 表格数据
    public static R ok(Long count, Object data) {
        return R.builder().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).count(count).data(data).build();
    }

    public static R fail() {
        return R.builder().code(ERROR_CODE).message(ERROR_MESSAGE).data(ERROR_DATA).build();
    }

    public static R fail(Object data) {
        return R.builder().code(ERROR_CODE).message(ERROR_MESSAGE).data(data).build();
    }
}
